/**
 * 定义天报表模块
 */
(function(window, angular, undefined){
	var module = angular.module('water.apps.zhuhai.remoteControl.remoteControlManager', ['RemoteControlController','RemoveControlService']);
	
	module.controller('zhuhaiRemoteControlController',function($scope,$controller,$OrderService){

		var control = $controller("remoteControlController",{$scope:$scope});
		var MN="";
		$scope.waterGetterOrderItems = [
			                               {
			                            	   ORDER_CODE:"PT_LY_PC",
			                            	   ORDER_ENABLE:"TRUE",
			                            	   ORDER_DESC:"留样",
			                            	   ORDER_STATUS:"2"
			                               }
			     ];
		
		$scope.sendSingleOrderEX = function(orderItem,orders,value){
			if(orderItem.ORDER_CODE == "MEAS_PC"){
				delete orderItem.PARMNAME;
			}
			$scope.sendSingleOrder(orderItem,orders,value);
		}
		$scope.sendFrequencyOrder = function() {
			var frequency = $scope.jianceTime;
			var index = frequency.indexOf(".");
			if(frequency!=null && frequency<2) {
				$.messager.alert("提示","测量频率不能小于2小时");
				return false;
			}
			if(index>0) {
				$.messager.alert("提示","请输入整数");
				return false;
			}
			$scope.orderItems = [
	                               {
	                      			   order_code:'SYS_CYCLE_SET',
	                      			   order_value:frequency
	                               }]
			$.messager.confirm("确认","确定要发送命令吗？",function(r){
				if(r){
					$OrderService.sendOrders(MN,$scope.orderItems,function(e){
						$.messager.alert("提示","命令已发送");
						insertSendCycleLog();
					});
				}
			});
		}
		
		function insertSendCycleLog() {
				$waterDataCommon.post("/ZhuhaiMonitorStation/getOpenedStationNo.do",{}).then(function(result){
					$scope.openedStationNo = result.openedStationNo;
					$scope.openedStationDeviceNum = result.openedStationDeviceNum;
				});
				var queryObj = {
	    				MN:$scope.openedStationDeviceNum,
	    				OPERATION_ITEM:"设定测量周期："+$scope.jianceTime+"小时"
	    		};
				$waterDataCommon.post("/RemoteControl/insertSendCycleLog.do",queryObj).then(function(result){
				});
		}
		
		$scope.queryStationID=function(){
			$waterDataCommon.post("/ZhuhaiMonitorStation/getOpenedStationNo.do",{}).then(function(result){
				$scope.openedStationNo = result.openedStationNo;
				$scope.openedStationDeviceNum = result.openedStationDeviceNum;
				MN=$scope.openedStationDeviceNum;
			});
		}
		
		$scope.queryStationID();
	});
}(window, angular));